﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using CoiffeurProject.DBMS.Entities;
using CoiffeurProject.Utils;
using System.Windows.Media.Imaging;

namespace CoiffeurProject.UserControls
{
    #region Customer Infos Panel

    internal class CustomerDetailsPanel
    {
        Customer linkedCustomer;

        Grid main_container;
        Label name, address, age, age_text, frequency, frequency_text, email, email_text, phone, phone_text, description;
        Image customer_photo;
        BitmapImage male_icon, female_icon;

        #region Commented Sample

        //<Grid Grid.Column="1" Grid.Row="1" Height="944" HorizontalAlignment="Left" Margin="20,9,0,0" Name="grid1" 
        //        VerticalAlignment="Top" Width="745">
        //        <Grid.ColumnDefinitions>
        //            <ColumnDefinition Width="289*" />
        //            <ColumnDefinition Width="456*" />
        //        </Grid.ColumnDefinitions>
        //        <Grid.RowDefinitions>
        //            <RowDefinition Height="244"/>
        //            <RowDefinition Height="700"/>
        //        </Grid.RowDefinitions>
        //        <Label FontSize="45" VerticalContentAlignment="Top" Content="Cristo Compagnone" Grid.Column="1" 
        //            Height="80" HorizontalAlignment="Left" Margin="20,5,0,0" Name="label1" VerticalAlignment="Top" 
        //            Width="430" Foreground="#FFAA2121" />
        //        <Label FontSize="18" Grid.Column="1" Height="40" HorizontalAlignment="Left" Margin="32,85,0,0" 
        //            Name="label2" Content="▪ Via della grotta 25, 31000, Nazaret" VerticalAlignment="Top" 
        //            Width="400" />
        //        <Label FontSize="18" Content="   33" Grid.Column="1" Height="40" HorizontalAlignment="Left" 
        //            Margin="32,108,0,0" Name="label4" VerticalAlignment="Top" Width="360" Foreground="#FFAA2121" />
        //        <Label FontSize="18" Content="▪        anni" Grid.Column="1" Height="40" HorizontalAlignment="Left" 
        //            Margin="32,108,0,0" Name="label3" VerticalAlignment="Top" Width="360"  />
        //        <Label FontSize="18" Content="▪ Cliente per        volte" Grid.Column="1" Height="40" 
        //            HorizontalAlignment="Left" Margin="32,132,0,0" Name="label5" VerticalAlignment="Top" 
        //            Width="360" />
        //        <Label FontSize="18" Content="                      2" Grid.Column="1" Height="40" 
        //            HorizontalAlignment="Left" Margin="32,132,0,0" Name="label6" VerticalAlignment="Top" 
        //            Width="360" Foreground="#FFAA2121" />
        //        <Label FontSize="18" Content="▪ email:" Grid.Column="1" Height="40" HorizontalAlignment="Left" 
        //            Margin="32,158,0,0" Name="label7" VerticalAlignment="Top" Width="360" />
        //        <Label FontSize="18" Content="compy00@mail.bet" Grid.Column="1" Height="40" 
        //            HorizontalAlignment="Left" Margin="98,157,0,0" Name="label8" VerticalAlignment="Top" 
        //            Width="280" Foreground="#FFAA2121" />
        //        <Label FontSize="18" Content="▪ telefono:" Grid.Column="1" Height="40" HorizontalAlignment="Left" 
        //            Margin="32,181,0,0" Name="label9" VerticalAlignment="Top" Width="360" />
        //        <Label FontSize="18" Content="12345670" Grid.Column="1" Height="40" HorizontalAlignment="Left" 
        //            Margin="123,182,0,0" Name="label10" VerticalAlignment="Top" Width="230" Foreground="#FFAA2121" />
        //        <Image Height="223" HorizontalAlignment="Left" Margin="0,19,0,0" Name="image1" Stretch="Fill" 
        //            VerticalAlignment="Top" Width="290" Source="/CoiffeurProject;component/Images/Customer/male_icon.PNG" />
        //        <Label FontSize="18" Grid.Row="1" Height="620" HorizontalAlignment="Left" Margin="10,75,0,0" 
        //             Name="textBox1" VerticalAlignment="Top" Width="470" Content="Ciao" Grid.ColumnSpan="2" />
        //    </Grid>

        #endregion

        private void InitializeLabels()
        {
            name = new Label()
            {
                Content = linkedCustomer.FullName,
                Width = 430,
                Height = 80,
                VerticalContentAlignment = VerticalAlignment.Top,
                HorizontalContentAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Thickness(20, 5, 0, 0),
                FontSize = 45,
                Foreground = new SolidColorBrush(new Color() { A = 255, R = 170, B = 33, G = 33 })
            };

            Grid.SetColumn(name, 1);
            main_container.Children.Add(name);

            address = new Label()
            {
                Content = "▪ " + linkedCustomer.FormatedAddress,
                Width = 400,
                Height = 40,
                VerticalContentAlignment = VerticalAlignment.Top,
                HorizontalContentAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Thickness(32, 85, 0, 0),
                FontSize = 18
            };

            Grid.SetColumn(address, 1);
            main_container.Children.Add(address);

            age = new Label()
            {
                Content = "   " + linkedCustomer.Age,
                Width = 360,
                Height = 40,
                VerticalContentAlignment = VerticalAlignment.Top,
                HorizontalContentAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Thickness(32, 108, 0, 0),
                FontSize = 18,
                Foreground = new SolidColorBrush(new Color() { A = 255, R = 170, B = 33, G = 33 })
            };

            Grid.SetColumn(age, 1);
            main_container.Children.Add(age);

            age_text = new Label()
            {
                Content = "▪        anni",
                Width = 360,
                Height = 40,
                VerticalContentAlignment = VerticalAlignment.Top,
                HorizontalContentAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Thickness(32, 108, 0, 0),
                FontSize = 18
            };

            Grid.SetColumn(age_text, 1);
            main_container.Children.Add(age_text);

            frequency_text = new Label()
            {
                Content = "▪ Cliente per        volte",
                Width = 360,
                Height = 40,
                VerticalContentAlignment = VerticalAlignment.Top,
                HorizontalContentAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Thickness(32, 132, 0, 0),
                FontSize = 18
            };

            Grid.SetColumn(frequency_text, 1);
            main_container.Children.Add(frequency_text);

            frequency = new Label()
            {
                Content = "                      " + linkedCustomer.Frequency,
                Width = 360,
                Height = 40,
                VerticalContentAlignment = VerticalAlignment.Top,
                HorizontalContentAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Thickness(32, 132, 0, 0),
                FontSize = 18,
                Foreground = new SolidColorBrush(new Color() { A = 255, R = 170, B = 33, G = 33 })
            };

            Grid.SetColumn(frequency, 1);
            main_container.Children.Add(frequency);

            email_text = new Label()
            {
                Content = "▪ email:",
                Width = 360,
                Height = 40,
                VerticalContentAlignment = VerticalAlignment.Top,
                HorizontalContentAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Thickness(32, 158, 0, 0),
                FontSize = 18
            };

            Grid.SetColumn(email_text, 1);
            main_container.Children.Add(email_text);

            email = new Label()
            {
                Content = linkedCustomer.Email,
                Width = 280,
                Height = 40,
                VerticalContentAlignment = VerticalAlignment.Top,
                HorizontalContentAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Thickness(98, 158, 0, 0),
                FontSize = 18,
                Foreground = new SolidColorBrush(new Color() { A = 255, R = 170, B = 33, G = 33 })
            };

            Grid.SetColumn(email, 1);
            main_container.Children.Add(email);

            phone_text = new Label()
            {
                Content = "▪ telefono:",
                Width = 360,
                Height = 40,
                VerticalContentAlignment = VerticalAlignment.Top,
                HorizontalContentAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Thickness(32, 182, 0, 0),
                FontSize = 18
            };

            Grid.SetColumn(phone_text, 1);
            main_container.Children.Add(phone_text);

            phone = new Label()
            {
                Content = linkedCustomer.Phone,
                Width = 230,
                Height = 40,
                VerticalContentAlignment = VerticalAlignment.Top,
                HorizontalContentAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Thickness(123, 182, 0, 0),
                FontSize = 18,
                Foreground = new SolidColorBrush(new Color() { A = 255, R = 170, B = 33, G = 33 })
            };

            Grid.SetColumn(phone, 1);
            main_container.Children.Add(phone);

            male_icon = new BitmapImage(new Uri(ImagesPath.MaleIcon));
            female_icon = new BitmapImage(new Uri(ImagesPath.FemaleIcon));

            customer_photo = new Image()
            {
                Height = 223,
                Width = 290,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Top,
                Stretch = Stretch.Fill,
                Source = linkedCustomer.Sex == "Maschio" ? male_icon : female_icon,
                Margin = new Thickness(0, 19, 0, 0)
            };

            main_container.Children.Add(customer_photo);

            description = new Label()
            {
                Content = linkedCustomer.Notes,
                Width = 470,
                Height = 620,
                VerticalContentAlignment = VerticalAlignment.Top,
                HorizontalContentAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Thickness(10, 75, 0, 0),
                FontSize = 18
            };

            Grid.SetRow(description, 1);
            Grid.SetColumnSpan(description, 2);
            main_container.Children.Add(description);
        }

        internal CustomerDetailsPanel(Customer customer)
        {
            this.linkedCustomer = customer;

            InitializeGrid();

            InitializeLabels();
        }

        internal void ChangeLinkedCustomer(Customer customer)
        {
            this.linkedCustomer = customer;

            name.Content = customer.FullName;
            address.Content = "▪ " + customer.FormatedAddress;
            age.Content = "   " + customer.Age;
            frequency.Content = "                      " + customer.Frequency;
            email.Content = customer.Email;
            phone.Content = customer.Phone;
            customer_photo.Source = linkedCustomer.Sex == "Maschio" ? male_icon : female_icon;
            description.Content = linkedCustomer.Notes;
        }

        internal void HidePanel()
        {
            main_container.Visibility = Visibility.Hidden;
        }

        private void InitializeGrid()
        {
            main_container = new Grid()
            {
                Width = 745,
                Height = 944,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Top,
                Margin = new Thickness(20, 9, 0, 0)
            };

            Grid.SetColumn(main_container, 1);
            Grid.SetRow(main_container, 1);

            main_container.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(289) });
            main_container.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(456) });

            main_container.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(244) });
            main_container.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(700) });
        }

        public UIElement MainContainer { get { return main_container; } }
    }

    #endregion
}
